 <?php
 //szczecin
  $lat=53.430606;
  $lng=14.556541;
  $zoom=12;
  $width=650;
  $height=300;

   if ( $_SERVER['REQUEST_METHOD'] == 'POST' )
{
   //print_r( $_POST);
   $search=$_POST['search'];
   $kat = $_POST['kategoria'];
   $opis = mysql_real_escape_string( $_POST['nazwa'] );
   $podkat = mysql_real_escape_string( $_POST['podkategoria'] );
   $szukany_tekst = htmlspecialchars($_POST['nazwa']);

   echo "<br>";

   if (empty($search))
   {//nie zaznaczono zadnego checkboxa
      echo '<br>Aby wyszukać punkty zaznacz pole obok kryterium wyszukiwania.<br>';
      return;
   }
   else
   {
      $select = "SELECT points . * , cat.name AS cname, ucat.id AS id_ucat
           FROM (points LEFT JOIN cat
           ON points.id_cat = cat.id )
LEFT JOIN ucat ON cat.id_ucat = ucat.id";

      $where = array();
      if ( in_array('kat', $search) && !empty($kat) )
      {
         $where[] =  "cat.id_ucat = " . (int)$kat;
      }
      if ( in_array('podkat', $search) && !empty($podkat))
      {
         $where[] = "id_cat = " . (int)$podkat;
      }
      if ( in_array('opis', $search) && !empty($opis))
      {
         $where[] = "( points.desc LIKE '%" . $opis . "%' OR points.name LIKE '%" . $opis . "%' )";
         //  $where[] = "points.name LIKE '%" . $opis . "%'";
      }
      if ( !empty($where) )
      {
         $select .= ' WHERE ' . implode(' AND ', $where);
      }
      global $database;
      $database->query($select);
     
   }
   if ( mysql_num_rows($database->result) <1 )
   {
      echo 'brak wynikow wyszukiwania';
      return;
   }
}
?>
<form name="kml_export" method="POST" action="?module=<?php
      echo $_GET['module'];
      ?>&amp;action=export" >
<table border="2" cellpadding="0" cellspacing="0" width="649"   >
   <tr class="b">
      <td width= "10" > &#160; </td>
      <td width= "65" > lon  </td>
      <td width= "65" > lat </td>
      <td width= "25" > map </td>
      <td width= "100" > name </td>
      <td width= "135" > opis</td>
      <td width= "125" > kategoria</td>
   </tr>
 <?php
   while ($r=mysql_fetch_array($database->result))
   {
      echo '<tr> <td  ><input type="checkbox" name="checkbox[]" id="'.$r['id'].'" value="'.$r['id'].'" /></td>
                    <td id="lon'.$r['id'].'" >'.$r['lon'].'</td> <td id="lat'.$r['id'].'" >'.$r['lat'].'</td><td><img alt="ShowOnMap" class="map_img" src="images/showmap_small.jpg" onClick="SetPosition('.$r['lat'].', '.$r['lon'].','.$r['id'].' )">'
     .'</td> <td id="n'.$r['id'].'">'. $r['name'].'</td>
                  <td id="d'.$r['id'].'">'. $r['desc'].'</td>
                  <td>'. $r['cname'].' /'.$r['uname']. '</td>';
      echo '</tr>';
   }
?>

</table>
 <input type="button" name="check" size="20" value="Zaznacz wszystkie" id="checkbtn" onclick="unCheckAll()">
<br>
<br>
Zaznaczone punkty<br>
<input type="radio" name="radiobtn" value="kml" onClick="showInput('skml')">eksportuj do KML <span id="skml"></span>
<br><input type="radio" name="radiobtn" value="gps" onClick="showInput('sgpx')">eksportuj do GPX <span id="sgpx"></span>
   <?php 
   if (isLoggedIn()>0)
   {
      include('formAddToList.php');
   }
   else
   {
      echo '<span id="sdel"></span><span id="sadd"></span>';
   }
?> <br>
<input type="button" name="showAllOnMap" size="20" value="Pokaż na mapie" id="showAllOnMap" onclick="showCheckedPoints()">
<script type="text/javascript">
      //<![CDATA[
var map;
var bounds;
      //]]>
      </script>
</form>

<div id="map" style="display:none; width: <?php echo $width; ?>px; height: <?php echo $height; ?>px"></div>